package com.qg.oss.core.minio;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.qg.oss.core.aliyun.config.AliyunOSSProperties;
import com.qg.oss.core.minio.client.MinIOClient;
import com.qg.oss.core.minio.config.MinIOProperties;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author QG
 * @Date 2023/6/12 16:12
 * @description
 **/
@Configuration
@EnableConfigurationProperties(MinIOProperties.class)
@ConditionalOnProperty(value = "oss.type",havingValue = "minio",matchIfMissing = false)
public class MinIOAutoConfiguration {

    @Autowired
    private MinIOProperties minIOProperties;

    @Bean
    public MinioClient ossClient() {
        // 创建OSSClient实例。
        return new MinioClient.Builder().
                endpoint(minIOProperties.getEndpoint()).credentials
                        (minIOProperties.getAccessKeyId(),minIOProperties.getAccessKeySecret()).build();
    }

    @Bean
    public MinIOClient minIOClient() {
        return new MinIOClient();
    }
}
